Add optional ASAN toolchain support for musl platforms - #2003
Merged
Conversation
Add `make BOARD=<platform> toolchain-asan` target that builds the same
toolchain but with libsanitizer enabled. Uses Buildroot's existing
BR2_EXTRA_GCC_CONFIG_OPTIONS to override --disable-libsanitizer.
Add GCC patch that guards musl-incompatible headers in libsanitizer
(struct sysinfo, linux/sysctl.h, linux/if_ppp.h). The patch is
harmless when libsanitizer is disabled.
Usage:
make BOARD=hi3516cv100_lite toolchain-asan
arm-openipc-linux-musleabi-gcc -fsanitize=address -static-libasan \
-fno-omit-frame-pointer -g -latomic -o myapp myapp.c
ASAN_OPTIONS="quarantine_size_mb=1:detect_leaks=0:\
stack_use_after_return=0:symbolize=0" ./myapp
Tested: found __aeabi_d2iz infinite recursion bug on hi3516cv100.
Ref: #1992
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
make BOARD=<platform> toolchain-asanthat builds a toolchain with AddressSanitizer support. Same toolchain, no separate artifact — just addslibasan.a/libasan.soto the output.How it works
Buildroot's gcc-final.mk appends
BR2_EXTRA_GCC_CONFIG_OPTIONSlast, so--enable-libsanitizeroverrides the earlier--disable-libsanitizerfor musl. No gcc.mk modification needed.A GCC patch guards musl-incompatible headers in libsanitizer (
struct sysinfo,linux/sysctl.h,linux/if_ppp.h). The patch is harmless when libsanitizer is disabled.Usage
Known limitation: vendor SDK MMZ memory
ASAN's shadow memory does not cover hardware-mapped regions (MMZ/Media Memory Zone used by HiSilicon, Sigmastar, etc). When vendor SDK functions map device memory via
/dev/mmz, ASAN's__asan_unpoison_stack_memoryreceives addresses outside its shadow range, causing:Workaround: exclude vendor SDK interaction files from ASAN instrumentation. For majestic:
Or in source code, annotate functions that call vendor SDK mmap:
Test plan
make BOARD=hi3516cv100_lite toolchain-asanbuilds successfullylibasan.aandlibasan.sopresent in output-fsanitize=address -static-libasan -latomicmake BOARD=hi3516cv100_lite toolchainstill works (patch is harmless)__aeabi_d2izinfinite recursion (uclibc-compat: fix __aeabi_d2iz infinite recursion #2002)Ref: #1992
🤖 Generated with Claude Code